package com.crm.kz.common;

import android.app.DownloadManager;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
import android.widget.Toast;

import com.crm.kz.common.AutoUpdater;

//监听app是否下载成功的广播接收者
public class APKInstallReceiver extends BroadcastReceiver {

    //DownloadManager下载完成后会自动发送一个包含ACTION_DOWNLOAD_COMPLETE动作的广播
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent.getAction().equals(DownloadManager.ACTION_DOWNLOAD_COMPLETE)){
            //下载完成
            Toast.makeText(context, "下载完成！", Toast.LENGTH_SHORT).show();
            Log.d("tag","下载完成-------");
            //开始安装
            AutoUpdater autoUpdater = new AutoUpdater(context);
            autoUpdater.installAPK();
        }
    }
}